#
# Makefile for building OpenVG plugin
#

AR = ar rc
CP = cp
RM = rm


CROSSDIR=   $(PLATDIR)/Cross/plugins/$(LIBNAME)
WIN32DIR=   $(PLATDIR)/Win32/plugins/$(LIBNAME)
MAKERDIR=   $(BASEDIR)/src/$(LIBNAME)
BUILDDIR=   $(BASEDIR)/obj/$(LIBNAME)

# Support directory locations
CROSSVMDIR= $(PLATDIR)/Cross/vm
WIN32VMDIR= $(PLATDIR)/Win32/vm
MAKERVMDIR= $(BASEDIR)/src/vm
BUILVMDDIR= $(BASEDIR)/obj/vm



DX7DIR= c:/dx7sdk/include

INCLUDES= -I. -I$(DX7DIR) \
	  -I$(MAKERVMDIR) -I$(WIN32VMDIR) -I$(CROSSVMDIR) \
	  -I$(MAKERDIR) -I$(WIN32DIR) -I$(CROSSDIR) -I$(OPENVGINC) -I$(OPENVGINC)/vg


#############################################################################
# C compiler settings (for egcs-1.1.2)
#
CC=	gcc
OFLAGS= -O2
CFLAGS=	-g -mpentium -mwindows -fomit-frame-pointer -funroll-loops \
	-fschedule-insns2 $(OFLAGS)
DEFS=	-DWIN32_FILE_SUPPORT -DNO_SERVICE -DNO_STD_FILE_SUPPORT -DNDEBUG \
	-DLSB_FIRST -DVM_NAME=\"$(VM)\" -DX86 $(XDEFS)

#############################################################################
# DLL settings
#
# Note: DLLTOOL/DLLWRAP does the work for everything related to plugins
#
DLLTOOL=	dlltool
DLLWRAP=	dllwrap

.SUFFIXES:	.c .o .s .rc .res .dep

OBJDIR=    $(BASEDIR)/obj/$(LIBNAME)
VMDIR=     $(BASEDIR)/obj/vm
PLUGINLIB= $(LIBNAME).lib
PLUGINDLL= $(OBJDIR)/$(LIBNAME).dll

LIBSRC= $(wildcard $(CROSSDIR)/*.c) $(wildcard $(WIN32DIR)/*.c) $(wildcard $(MAKERDIR)/*.c)

EXTRALIBS= -lglu32 -lopengl32

LIBOBJ= $(LIBSRC:.c=.o)
LIBOBJF= $(addprefix $(OBJDIR)/, $(notdir $(LIBSRC:.c=.o)))


print-settings:
	@echo ---------------- Makefile settings ------------------
	@echo LIBNAME=$(LIBNAME)
	@echo BASEDIR=$(BASEDIR)
	@echo PLATDIR=$(PLATDIR)
	@echo BUILDDIR=$(BUILDDIR)

	@echo OPENVGDIR=$(OPENVGDIR)
	@echo OPENVGINC=$(OPENVGINC)
	@echo OPENVGSRC=$(OPENVGSRC)
	@echo INCLUDES=$(INCLUDES)
	@echo -----------------------------------------------------


all:	$(PLUGINLIB) $(PLUGINDLL)
	@echo "here"

$(OBJDIR):
	mkdir $(OBJDIR)

$(VMDIR):
	mkdir $(VMDIR)


#$(LIBOBJ): $(LIBSRC)
#	$(CC) -o $(LIBOBJ) $(CFLAGS) $(INCLUDES) $(DEFS) -c $(LIBSRC)


$(PLUGINLIB): $(VMDIR) $(OBJDIR) $(LIBOBJ)
	$(AR) $(OBJDIR)/$(PLUGINLIB) $(LIBOBJF)

$(PLUGINDLL): $(VMDIR) $(OBJDIR) $(LIBOBJ)
	$(DLLTOOL) \
		--output-def $(OBJDIR)/$(LIBNAME).def \
		--output-exp $(OBJDIR)/$(LIBNAME).exp \
		--output-lib $(OBJDIR)/$(LIBNAME).lib \
		$(LIBOBJF)
	$(DLLWRAP) -mwindows \
		-def $(OBJDIR)/$(LIBNAME).def \
		-o   $(OBJDIR)/$(LIBNAME).dll \
		$(OBJDIR)/$(LIBNAME).exp \
		$(LIBOBJF) \
		$(EXTRALIBS)
	strip --strip-all $(OBJDIR)/$(LIBNAME).dll
	-rm $(OBJDIR)/$(LIBNAME).lib

%.dll: $(PLUGINDLL)
	@echo done

.c.o:
	$(CC) -o $(OBJDIR)/$(notdir $@) $(CFLAGS) $(INCLUDES) $(DEFS) -c $<
